<?php
 
/*
  $Id: player_parser.php,v 2.00 09/11/2004 16:00:10 ManMAchine Exp $

  Mp3 player module for osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  
  osPlayer - ManMAchine - 09/11/2004 manmachine@counteractdesign.com
  Copyright (c) 2004 ManMAchine

  Released under the GNU General Public License
*/
//********************************************
//********************************************
//      osPlayer V2 (c) ManMachine
//********************************************
//********************************************



require('includes/application_top.php');


///////////////////////////////////////////////////

// Parse variables to FLASH Fonction
/////////
   function Parse($variable,$valeur) {
       echo "&" . $variable . "=" . urlencode($valeur);
   }

// Browse files Fonction
/////////
function tep_browse_mp3($pDirectory, $pExtension) {
    if($handle = opendir($pDirectory))   {
         while(false !== ($file = readdir($handle)))  {
            $getExt = explode(".", $file);
            $countExt = count($getExt);
            $fExt = $countExt - 1;
            $myExt = $getExt[$fExt];
            
            if (($myExt == $pExtension) && ($file != ".") && ($file != "..")) {
				$files[] = $file;
				}
        }
    }
return $files;    
closedir($handle);
}
/////////////////////////////////////////////////                              



$mp3id=$HTTP_POST_VARS['idmp3']; // get the product id from flash

/// SQL query
$mp3_files_query = tep_db_query("select products_folder from " . TABLE_PRODUCTS_MP3 . " where  products_id = '$mp3id'");
$mp3_files = tep_db_fetch_array($mp3_files_query);


// folder we want to search in
$gDirectory = DIR_FS_CATALOG_MP3 . $mp3_files['products_folder'] ;

// files extension we want to list
$gExtension = "mp3"; 

/// Create a tab with files
$ExpExt = explode(" ", $gExtension);
sort ($ExpExt);

foreach ($ExpExt as $findExt) {
        
		$getFile = @tep_browse_mp3($gDirectory, $findExt);
        $countFile = count($getFile);      
        
        if ($countFile != 0) { 
			foreach ($getFile as $myFile) {
				$list[] = $myFile;
			}  
		}            
    } 

//sort the playlist properly
$$list = array();
sort($list);

//////////
/// create and parse the variables to the player 
/// the number of tracks
$trcknbr = $countFile ;
Parse ("trcknbr" , $trcknbr ) ;

/// the tracks files names
for($i=0;$i<$countFile;$i++) {
$trck[$i] = "$list[$i]";
Parse ("trck$i" , $trck[$i] ) ;
}

/// the path where the files are located
$path = HTTP_SERVER . DIR_WS_CATALOG_MP3 . $mp3_files['products_folder'] ;
Parse ("path" , $path ) ;

?>
